package com.ctshk.sapp.goods.controller;


import com.alibaba.fastjson.JSONObject;
import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.goods.dto.htmlFive.CommodityAllListDTO;
import com.ctshk.rpc.goods.dto.htmlFive.HtmlFiveCommodityClassificationAllLevelListDTO;
import com.ctshk.rpc.goods.service.IHtmlFiveCommodityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * H5端-商品表 前端控制器
 * </p>
 *
 * @author 姜斌文
 * @since 2021-04-13
 */
@Api(value="H5端-商品管理", tags="H5端-商品管理")
@RestController
@RequestMapping("/hFive/commodity")
public class HtmlFiveCommodityController extends BaseController {

    @DubboReference
    private IHtmlFiveCommodityService commodityService;

    @ApiOperation(value = "查询一二级下拉列表-测试用，接口用于ES", notes = "查询一二级下拉列表-测试用，接口用于ES")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.QUERY, operTitle = "查询一二级下拉列表", operDesc = "查询一二级下拉列表")
    @GetMapping("/findClassificationByAllLevel")
    public Result<List<HtmlFiveCommodityClassificationAllLevelListDTO>> findClassificationByAllLevel() {
        List<HtmlFiveCommodityClassificationAllLevelListDTO> response = commodityService.findClassificationByAllLevel(null);
        return Result.success(response);
    }

    @ApiOperation(value = "根据ID查询商品明细", notes = "根据ID查询商品明细")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.QUERY, operTitle = "根据ID查询商品明细", operDesc = "根据ID查询商品明细")
    @GetMapping("/findCommodityById/{id}")
    public Result<JSONObject> findCommodityById(@PathVariable(name = "id") Long id) throws Exception {
        JSONObject data = commodityService.findCommodityDetailedByCommodityId(id);
        return Result.success(data);
    }

    @ApiOperation(value = "根据商品ID查询规格和属性列表", notes = "根据商品ID查询规格和属性列表")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.QUERY, operTitle = "根据商品ID查询规格和属性列表", operDesc = "根据商品ID查询规格和属性列表")
    @GetMapping("/findCommodityAttributesListById/{id}")
    public Result<JSONObject> findCommodityAttributesListById(@PathVariable("id") Long id){
        return Result.success(commodityService.findCommodityAttributesListById(id));
    }

    @ApiOperation(value = "查询全部商品-测试用，接口用于ES", notes = "查询全部商品-测试用，接口用于ES")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.QUERY, operTitle = "查询全部商品", operDesc = "查询全部商品")
    @GetMapping("/findCommodityAllList")
    public Result<List<CommodityAllListDTO>> findCommodityAllList() throws Exception {
        List<CommodityAllListDTO> resut = commodityService.findCommodityAllList(LocalDateTime.now());
        return Result.success(resut);
    }
}
